$(".radio").toggle(function () {
    $(this).css("background-image","url(img/下载.png)");
    },
    function () {
        $(this).css("background-image","none");
    });
new Vue({
   el:"#app",
   data:{
       totalMoney:0,
       totalNum:0,
       products:[],
   },
   created:function () {
        this.initData();
   },
    methods: {
        count: function (products) {
            this.totalMoney=0;
            this.totalNum=0;
            products.forEach((val) => {
                this.totalMoney += val.price * val.qal;
                this.totalNum += val.qal;
        })
            ;
        },
        initData: function () {
            fetch("./json/products.json").then((data)=>{
                data.json().then((data)=>{
                this.products = data;
                this.count(data);
            })
        })
        },

        addQal: function (index) {
            this.products[index].qal++;
            this.count(this.products);
        },
        oddQal: function (index) {
            if (this.products[index].qal <= 1) {
                this.products[index].qal = 1;
            }
            else {
                this.products[index].qal--;
                this.count(this.products);
            }
        }
    }
});